var e = require;
var t = module;
var n = exports;
var s =
    (this && this.__spreadArrays) ||
    function () {
        for (var e = 0, t = 0, n = arguments.length; t < n; t++) e += arguments[t].length;
        for (var o = Array(e), i = 0, t = 0; t < n; t++)
            for (var r = arguments[t], a = 0, s = r.length; a < s; a++, i++) o[i] = r[a];
        return o;
    };
Object.defineProperty(n, "__esModule", {value: !0}),
    (n.NodeLocker = n.unlockNode = n.lockNode = n.isNodeLocked = n.LockLevel = void 0);
var c;
((t = c = n.LockLevel || (n.LockLevel = {}))[(t.Global = 0)] = "Global"), (t[(t.Node = 1)] = "Node");
var o = new Map([
    [c.Global, new Set()],
    [c.Node, new Set()]
]);
function l(e, t) {
    t = o.get(t);
    t.has(e.uuid) || t.add(e.uuid);
}
function u(e, t) {
    t = o.get(t);
    t.has(e.uuid) && t.delete(e.uuid);
}
(n.isNodeLocked = function (e) {
    var t = o.get(c.Global),
        n = o.get(c.Node);
    return 0 != t.size || n.has(e.uuid);
}),
    (n.lockNode = l),
    (n.unlockNode = u),
    (n.NodeLocker = function (a) {
        return (
            void 0 === a && (a = c.Global),
            function (e, t, n) {
                var r = n.value;
                n.value = function () {
                    for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
                    var n = function (e) {
                        for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
                        var o = e;
                        return 0 < t.length && (e = t[0]) instanceof cc.Event.EventTouch && (o = e.target), o;
                    }.apply(void 0, s([this.node], e));
                    null == n && ((a = c.Global), console.warn("[Node Locker]", "no node found, lock globally")),
                        l(n, a);
                    var o,
                        i = r.call.apply(r, s([this], e));
                    return (
                        i instanceof Promise
                            ? i.then(function () {
                                  u(n, a);
                              })
                            : u(n, a),
                        this instanceof cc.Component &&
                            ((o = this.onDestroy),
                            (this.onDestroy = function () {
                                for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
                                u(this.node, a), o.call.apply(o, s([this], e));
                            })),
                        i
                    );
                };
            }
        );
    });
